/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-7-3 下午3:57
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.jdmetro.adapter.consulation;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.dqhl.jdmetro.R;
import com.example.dqhl.jdmetro.bean.consulation.ConsulationHotNews;
import com.example.dqhl.jdmetro.config.Config;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
*description:资讯 热点要闻Adapter
*autour:guanluocang
*date:17/6/27 11:20
*/

public class ConsulationHotNewsAdpater extends RecyclerView.Adapter<ConsulationHotNewsAdpater.ConsulationHotNewsViewHolder>{

    private List<ConsulationHotNews> mConsulationHotNewsList = new ArrayList<>();
    private Context mContext;
    private LayoutInflater inflater;
    private onItemClickListener onItemClickListener;

    public ConsulationHotNewsAdpater(Context context){
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ConsulationHotNewsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ConsulationHotNewsViewHolder consulationHotNewsViewHolder = new ConsulationHotNewsViewHolder(inflater.inflate(R.layout.layout_consulation_hotnew,parent,false));
        return consulationHotNewsViewHolder;
    }

    public void refresh_newHots(List<ConsulationHotNews> consulationHotNewses){
        this.mConsulationHotNewsList = consulationHotNewses;
        notifyDataSetChanged();
    }
    //点击事件和长按事件
    public interface onItemClickListener {
        void onItemClick(View view, int position);

    }
    public void setOnItemClickListener(onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    @Override
    public void onBindViewHolder(final ConsulationHotNewsViewHolder holder, int position) {
        x.image().bind(holder.iv_hotNews, Config.pic_base_url+mConsulationHotNewsList.get(position).getPic());
        if(onItemClickListener != null){
            holder.iv_hotNews.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = holder.getLayoutPosition();
                    onItemClickListener.onItemClick(holder.itemView,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mConsulationHotNewsList.size();
    }

    class ConsulationHotNewsViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_hotNews;
        public ConsulationHotNewsViewHolder(View view){
            super(view);
            iv_hotNews = (ImageView) view.findViewById(R.id.iv_hotNews);
        }
    }
}
